package com.example.myapplication.ui.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.myapplication.R;
import com.example.myapplication.base.BaseLazyFragment;
import com.example.myapplication.bean.SystemsBean;
import com.example.myapplication.presenter.SystemsPresenter;
import com.example.myapplication.ui.adapter.SystemsAdapter;
import com.example.myapplication.view.SystemsView;
import java.util.ArrayList;
import java.util.List;

import qdx.stickyheaderdecoration.NormalDecoration;


public class SystemsFragment extends BaseLazyFragment<SystemsPresenter> implements SystemsView {


    private RecyclerView rv;
    private SystemsAdapter systemsAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getSystemsData();
    }

    @Override
    protected void initView(View view) {
        rv = (RecyclerView) view.findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        final ArrayList<SystemsBean.DataBean> list = new ArrayList<>();
        systemsAdapter = new SystemsAdapter(getContext(),list);
        rv.setAdapter(systemsAdapter);

        //头部流失布局
        NormalDecoration normalDecoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return list.get(i).getName();
            }
        };
        rv.addItemDecoration(normalDecoration);
    }

    @Override
    protected SystemsPresenter initPresenter() {
        return new SystemsPresenter();
    }


    @Override
    protected int getLayout() {
        return R.layout.fragment_systems;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void setData(SystemsBean systemsBean) {
        List<SystemsBean.DataBean> data = systemsBean.getData();
        if (data!=null&&data!=null&&data.size()>0){
            systemsAdapter.addData(data);
        }
    }
}